<template>
	<view>
		<view>
			<image class="box" :src="imgBox" mode="widthFix"></image>
			<view class="message"></view>
			<view class="box_one">
				<button v-if="to_next" class="button" @tap="login()">
					<view class="message_a" >点击开始</view>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	const {
		appLogin,
		httpGet,
		httpPost,
		ZC
	} = require("@/utils/common.js")
	const app = getApp();
	export default {
		data() {
			return {
				code: '',
				timer: null,
				to_next:false,
				user_info:{},
				imgBox:'https://zhaojjw.cn/newjbh/202192223246021'
			}
		},
		onLoad() {
			this.getlogin()
			// this.timer = setTimeout(()=>{
			// 	this.login()
			// },3000)
			// this.getCode()
		},
		methods: {
			// getCode() {
			// 	uni.login({
			// 		success(res) {
			// 			console.log(res)
						
			// 		}
			// 	})
			// },
			getlogin(){
				uni.login({
					success:(res)=>{
						this.code = res.code
						httpPost({
							url:'/api/wx_app_login',
							data:{
								code:this.code
							}
						}).then((res) => {
							this.user_info = res.result
							var token = res.result.token
							ZC('user_token',token,-1)
							ZC('user_info',res.result,-1)
							app.globalData.user_info = res.result
							app.globalData.user_token = res.result.token
							app.ws();
							this.timer = setTimeout(()=>{
								this.login()
							},3000)
							
							
							this.to_next = true;
							console.log(res,111)
						}).catch(()=>{
							this.to_next = true;
						})
					},
					fail() {
						this.to_next = true;
					}
				})

			},
			login() {
				if (this.timer) clearTimeout(this.timer)
				if (this.user_info&&this.user_info.identity == "teacher") {
					uni.reLaunch({
						url: "people_center"
					})
				} else if (this.user_info&&this.user_info.identity == "student") {
					uni.reLaunch({
						url: "../student/business"
					})
				} else if (this.user_info&&this.user_info.identity == "staff") {
					uni.reLaunch({
						url: "../company/people_center"
					})
				} else {
					uni.reLaunch({
						url: '../index/index'
					})
				}
			}
		}
		
	}
</script>

<style>
	page {
		background-image: url('https://zhaojjw.cn/newjbh/202192219439267');
	}

	.box {
		margin-top: 450rpx;
		margin-left: 35%;
		width: 240rpx;
	}

	.box_one {
		position: relative;
		bottom: -350rpx;
		width: 100%;
	}

	.icon-shixu {
		color: rgb(64, 89, 218);
		font-size: 160rpx;
		width: 220rpx;
		height: 220rpx;
		padding-left: 13%;
		padding-top: 15%;

	}

	.message {
		color: #FFFFFF;
		font-size: 60rpx;
		text-align: center;
		margin-top: 50rpx;
	}

	.message_a {
		text-align: center;
		color: #FFFFFF;
	}

	.button {
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		width: 500rpx;
		height: 100rpx;
		border-radius: 500rpx;
		background-color: rgba(0,0,0,0);
		justify-content: center;
	}
</style>
